package me.zhengjie.modules.system.service.apply;

import cn.hutool.json.JSONUtil;
import me.zhengjie.exception.CommonUtilException;
import me.zhengjie.modules.system.domain.IdentityItem;
import me.zhengjie.modules.system.enums.ApplyWorkOrderTypeEnum;
import me.zhengjie.modules.system.service.IdentityItemService;
import me.zhengjie.modules.system.service.dto.DisChangeApplyDto;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProfitChangeServiceImpl implements IApplyCallbackService{

    @Autowired
    IdentityItemService identityItemService;

    @Override
    public Integer getApplyType() {
        return ApplyWorkOrderTypeEnum.ProfitChange.getType();
    }

    @Override
    public boolean execute(DisChangeApplyDto applyDto) {
        String json = applyDto.getApplyContent();
        if(StringUtils.isEmpty(json)){
            throw new CommonUtilException("申请内容不能为空");
        }
        IdentityItem identityItem = JSONUtil.toBean(applyDto.getApplyContent(), IdentityItem.class);
        identityItemService.update(identityItem);
        return true;
    }
}
